﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.common;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.battle
{
    /// <summary>
    /// 攻击敌人服务(攻击/开启宝箱)
    /// </summary>
    class AttackServer : LogicServer
    {
        public AttackServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Attack; ServerReadableName = ConfigStrings.SR_Attack; }
        #region server settings  
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            frm.chk_attack_player.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");
            frm.chk_attack_player_cityevent.Checked = conf.ContainsKey(ConfigStrings.city_event) && conf[ConfigStrings.city_event].ToLower().Equals("true");
            frm.chk_attack_player_gongjian.Checked = conf.ContainsKey(ConfigStrings.gongjian) && conf[ConfigStrings.gongjian].ToLower().Equals("true");
            frm.chk_attack_enable_attack.Checked = conf.ContainsKey(ConfigStrings.enable_attack) && conf[ConfigStrings.enable_attack].ToLower().Equals("true");
            frm.chk_attack_get_extra_order.Checked = conf.ContainsKey(ConfigStrings.get_extra_order) && conf[ConfigStrings.get_extra_order].ToLower().Equals("true");

            frm.chk_attack_npc_enemy.Checked = conf.ContainsKey(ConfigStrings.attack_npc) && conf[ConfigStrings.attack_npc].ToLower().Equals("true");
            frm.chk_attack_player_use_token.Checked = conf.ContainsKey(ConfigStrings.use_token) && conf[ConfigStrings.use_token].ToLower().Equals("true");
            frm.chk_attack_player_move_tokenfull.Checked = conf.ContainsKey(ConfigStrings.auto_move) && conf[ConfigStrings.auto_move].ToLower().Equals("true");
            frm.chk_attack_not_injail.Checked = conf.ContainsKey(ConfigStrings.not_injail) && conf[ConfigStrings.not_injail].ToLower().Equals("true");
            frm.chk_attack_jail_tech.Checked = conf.ContainsKey(ConfigStrings.jail_tech) && conf[ConfigStrings.jail_tech].ToLower().Equals("true");

            int level_min = 0, level_max = 0, min_score = 5000;
            if (conf.ContainsKey(ConfigStrings.level_min)) Int32.TryParse(conf[ConfigStrings.level_min], out level_min);
            if (conf.ContainsKey(ConfigStrings.level_max)) Int32.TryParse(conf[ConfigStrings.level_max], out level_max);
            if (conf.ContainsKey(ConfigStrings.min_score)) Int32.TryParse(conf[ConfigStrings.min_score], out min_score);
            frm.num_attack_player_level_min.Value = level_min;
            frm.num_attack_player_level_max.Value = level_max;
            frm.num_attack_score.Value = min_score;
            if (conf.ContainsKey(ConfigStrings.move_target)) frm.lbl_attack_target.Text = conf[ConfigStrings.move_target].Trim();
            int reserve_token = 0;
            if (conf.ContainsKey(ConfigStrings.attack_reserve_token)) Int32.TryParse(conf[ConfigStrings.attack_reserve_token], out reserve_token);
            frm.num_attack_reserve_token.Value = reserve_token;
            frm.chk_attack_reserve_token.Checked = conf.ContainsKey(ConfigStrings.attack_reserve_token_enable) && conf[ConfigStrings.attack_reserve_token_enable].ToLower().Equals("true");
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_attack_player.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.city_event, frm.chk_attack_player_cityevent.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.gongjian, frm.chk_attack_player_gongjian.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.enable_attack, frm.chk_attack_enable_attack.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.get_extra_order, frm.chk_attack_get_extra_order.Checked.ToString());

            conf.setConfig(ServerName, ConfigStrings.level_min, frm.num_attack_player_level_min.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.level_max, frm.num_attack_player_level_max.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.attack_npc, frm.chk_attack_npc_enemy.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.use_token, frm.chk_attack_player_use_token.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.auto_move, frm.chk_attack_player_move_tokenfull.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.not_injail, frm.chk_attack_not_injail.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.min_score, frm.num_attack_score.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.move_target, frm.lbl_attack_target.Text);
            conf.setConfig(ServerName, ConfigStrings.jail_tech, frm.chk_attack_jail_tech.Checked.ToString());

            conf.setConfig(ServerName, ConfigStrings.attack_reserve_token_enable, frm.chk_attack_reserve_token.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.attack_reserve_token, frm.num_attack_reserve_token.Value.ToString());
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.city_event, "true");
            conf.setConfig(ServerName, ConfigStrings.gongjian, "true");
            conf.setConfig(ServerName, ConfigStrings.enable_attack, "true");
            conf.setConfig(ServerName, ConfigStrings.get_extra_order, "true");

            conf.setConfig(ServerName, ConfigStrings.level_min, "0");
            conf.setConfig(ServerName, ConfigStrings.level_max, getUser().Level.ToString());
            conf.setConfig(ServerName, ConfigStrings.attack_npc, "true");
            conf.setConfig(ServerName, ConfigStrings.use_token, "true");
            conf.setConfig(ServerName, ConfigStrings.auto_move, "true");
            conf.setConfig(ServerName, ConfigStrings.not_injail, "true");
            conf.setConfig(ServerName, ConfigStrings.min_score, "5000");
            conf.setConfig(ServerName, ConfigStrings.move_target, "");
            conf.setConfig(ServerName, ConfigStrings.jail_tech, "false");

            conf.setConfig(ServerName, ConfigStrings.attack_reserve_token_enable, "false");
            conf.setConfig(ServerName, ConfigStrings.attack_reserve_token, "0");
            renderSettings();
        }
        #endregion
    }
}
